﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
 }
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        订单号：<input id="order_sn" col="order_sn" type="text" />
                    </li>
                    <li>
                        商店：<span id="shopids" col="shopids"></span>
                    </li>
                    <li>
                        商品：<input id="goods_name" col="goods_name" type="text" />
                    </li>
                    @*<li>
            商店名称：<input id="shop_name" col="shop_name" type="text" />
        </li>*@
                    <li class="select-time">
                        <label>下单时间： </label>
                        <input id="startTime" col="StartTime" type="text" class="time-input" autocomplete="off" placeholder="开始时间" />
                        <span>-</span>
                        <input id="endTime" col="EndTime" type="text" class="time-input" autocomplete="off" placeholder="结束时间" />
                    </li>
                    <li class="select-time">
                        <label>下单金额： </label>
                        <input id="sOrderMoney" col="SOrderMoney" placeholder="￥" type="text" class="time-input" autocomplete="off" />
                        <span>至</span>
                        <input id="eOrderMoney" col="EOrderMoney" placeholder="￥" type="text" class="time-input" autocomplete="off" />
                    </li>
                    <li>
                        订单状态：<span id="order_status" col="order_status"></span>
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>
        <div class="btn-group-sm hidden-xs" id="toolbar">
            @*<a id="btnAdd" class="btn btn-success" onclick="showSaveForm(true)"><i class="fa fa-plus"></i> 新增</a>
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>*@
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function () {
        $("#shopids").ysComboBox({
            url: '@Url.Content("~/QixingManage/Shop/GetListJson")',
            key: "Id",
            value: "shop_name"
        });
        $("#order_status").ysComboBox({ data: ys.getJson(@Html.Raw(typeof(OrderStatusEnum).EnumToDictionaryString())) });
        laydate.render({ elem: '#startTime', format: 'yyyy-MM-dd' });
        laydate.render({ elem: '#endTime', format: 'yyyy-MM-dd' });
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/QixingManage/OrderDetail/GetPageDetailList")';
        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'order_sn', title: '订单号' },
                {
                    field: 'order_type', title: '订单类型',  formatter: function (value, row, index) {
                        if (row.order_type == "@OrderTypeStatus.二手车.ParseToInt()") {
                            return "@OrderTypeStatus.二手车";
                        } else if (row.order_type == "@OrderTypeStatus.新车.ParseToInt()") {
                             return "@OrderTypeStatus.新车";
                        } else if (row.order_type == "@OrderTypeStatus.租车.ParseToInt()") {
                             return "@OrderTypeStatus.租车";
                        }
                    }
                },
                { field: 'shop_name', title: '商店' },
                { field: 'goods_name', title: '订单商品名称' },
                {
                    field: 'goods_image', title: '订单商品图片', formatter: function (value, row, index) {
                        if (index % 2 == 0) {
                            return '<img class="img-circle img-xs" src="' + row.goods_image + '" onclick=showImage("' + row.shop_image_url + '") />';
                        }
                        else {
                            return '<img class="img-circle img-xs" src="' + row.goods_image + '" onclick=showImage("' + row.shop_image_url + '") />';
                        }
                    }
                },
                { field: 'name', title: '货品名称' },
                { field: 'model', title: '货品型号' },
                { field: 'color', title: '货品颜色' },
                { field: 'product_cnt', title: '订单商品数量' },
                { field: 'goods_price', title: '商品单价' },
                { field: 'order_money', title: '订单金额' },
                { field: 'payment_money', title: '实际支付金额' },
                { field: 'order_status', title: '订单状态',  formatter: function (value, row, index) {
                        if (row.order_status == "@OrderStatusEnum.已关闭.ParseToInt()") {
                            return "@OrderStatusEnum.已关闭";
                        } else if (row.order_status == "@OrderStatusEnum.已发货.ParseToInt()") {
                             return "@OrderStatusEnum.已发货";
                        } else if (row.order_status == "@OrderStatusEnum.已完成.ParseToInt()") {
                             return "@OrderStatusEnum.已完成";
                        } else if (row.order_status == "@OrderStatusEnum.待付款.ParseToInt()") {
                             return "@OrderStatusEnum.待付款";
                        } else if (row.order_status == "@OrderStatusEnum.待发货.ParseToInt()") {
                             return "@OrderStatusEnum.待发货";
                        } else if (row.order_status == "@OrderStatusEnum.无效订单.ParseToInt()") {
                             return "@OrderStatusEnum.无效订单";
                        }
                    }
                },
                {
                    field: 'create_time', title: '下单时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                {
                    field: 'shipping_time', title: '发货时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                {
                    field: 'receive_time', title: '收货时间', formatter: function (value, row, index) {
                    return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                {
                    field: 'pay_time', title: '支付时间', formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd HH:mm:ss");
                    }
                },
                { field: 'shipping_user', title: '收货人' },
                { field: 'ship_mobile', title: '联系电话' },
                {
                    field: '', title: '区域',formatter: function (value, row, index) {
                        return row.province + "-" + row.city + "-" + row.district;
                    }
                },
                { field: 'address', title: '详细地址' },
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);
                var queryString = $('#searchDiv').getWebControls(pagination);
                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? '编辑' : '添加',
            content: '@Url.Content("~/QixingManage/OrderDetail/OrderDetailForm")' + '?id=' + id,
            width: '768px',
            height: '550px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteForm() {
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm('确认要删除选中的' + selectedRow.length + '条数据吗？', function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/QixingManage/OrderDetail/DeleteFormJson")' + '?ids=' + ids,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }
</script>
